﻿using Microsoft.Xna.Framework;

partial class Level : GameObjectList
{

    public override void HandleInput(InputHelper inputHelper)
    {
        quitButton.HandleInput(inputHelper);
        base.HandleInput(inputHelper);
        if (quitButton.Pressed)
        {
            this.Reset();
            GameEnvironment.GameStateManager.SwitchTo("levelMenu");
        }      
    }

    public override void Update(GameTime gameTime)
    {
        base.Update(gameTime);

        Player player = this.Find("player") as Player;

        // check if we died
        if (!player.IsAlive)
            timer.Running = false;

        // check if we ran out of time
        if (timer.GameOver)
            player.Explode();
                       
        // check if we won
        if (this.Completed && timer.Running)
        {
            player.LevelFinished();
            timer.Running = false;
        }

        quitButton.Update(gameTime);
        timer.Update(gameTime);
        hintfield.Update(gameTime);
        hintTimer.Update(gameTime);

        foreach (GameObjectList bg in backgrounds)
            bg.Update(gameTime);
    }

    public override void Reset()
    {
        base.Reset();
        hintTimer.StartVisible();
        timer.Reset();

        GameEnvironment.GameCamera.CameraPosition = Vector2.Zero;
    }
}
